﻿using ApiDoc.DAL;
using ApiDoc.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ApiDoc.Admin.Server.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class InterfaceController : ControllerBase
    {
        private readonly ApiDAL ApiDAL;

        public InterfaceController(ApiDAL ApiDAL)
        {
            this.ApiDAL = ApiDAL;
        }

        [HttpGet("List")]
        public List<ApiModel> List(string title, string id)
        {
            List<ApiModel> list = this.ApiDAL.Query(title, id);
            return list;
        }

        [HttpPost("Save")]
        public ApiModel Save(ApiModel model)
        {
            if (model.SN > 0)
            {
                this.ApiDAL.Update(model);
            }
            else
            {
                int SN = this.ApiDAL.Insert(model);
                model.SN = SN;
            }

            return model;
        }

        [HttpGet("FullPath")]
        public string FullPath(int fksn)
        {
            return this.ApiDAL.FullPath(fksn);
        }
    }
}
